// threadclient.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <Client.h>

int main(int argc, char* argv[])
{

#ifdef WIN32
	WSADATA wsaData;
	if( 0 > WSAStartup( MAKEWORD(2,2), &wsaData) )
		return -1;
#endif

	CClient client;

	CSock Sock;
	Sock.Init( CSock::TCP );
//	Sock.Init( CSock::UDP );

	Sock.Connect( "127.0.0.1", 12311 );
//	Sock.Connect( "192.168.3.97", 12311 );

	client.SetSocket( Sock );

	char szTemp[CSock::MAXBUFF];
	
	char szPacket[CSock::MAXBUFF];
	size_t nPacketSize = 0;
	memset( szPacket, 0, CSock::MAXBUFF );

	int nSendSize = 0;
	int nRecvSize = 0;
	while(1)
	{	
		memset( szPacket, 0, CSock::MAXBUFF );
		memset( szTemp, 0, CSock::MAXBUFF );
		nPacketSize = 0;

		std::cout << " input : ";
		std::cin >> szTemp;
		if( !strcmp(szTemp, "q") )
			break;

		nSendSize = client.Send( szTemp, strlen(szTemp));
		nSendSize = client.Send( szTemp, strlen(szTemp));
		std::cout << "[" << client.GetSocket()->GetSock() <<"] send ( " << nSendSize << " ): " << szTemp << std::endl;
		
		nRecvSize = client.Recv( szPacket, nPacketSize );
		std::cout << "[" << client.GetSocket()->GetSock() <<"] recv ( " << nSendSize << " ): " << szTemp << std::endl;
		if( 0 > nRecvSize )
			break;				
	}
	
	
	Sock.Close();

#ifdef WIN32
	WSACleanup();
#endif


	return 0;
}
